<?php include('./public/header.php') ?>
<link href="../css/login.css" rel="stylesheet">

<body>
<div class="container">
    <div class="content">
        <div class="wrap">
            <img src="../img/2.png" alt="">
            <p class="title">幼儿园场景实训教学系统</p>
            <input id="user" type="text" class="input form-control" placeholder="账号" value="teacher">
            <input id="password" type="password" class="input form-control" placeholder="密码" value="123456">
            <button class="btn" type="button">登录</button>
        </div>
    </div>
</div>

</body>
<?php include('./public/footer.php') ?>

<script type="text/javascript" src="../js/setting.js"></script>
<script type="text/javascript">
var datas = {
    urlLogin: parameters.urlLogin,
};
var methods = {
    login: function() {
        var user = $('#user').val();
        var password = $('#password').val();

        if (user == '' || password == '') {
            alert('请输入账号和密码');
        }
        $.ajax({
            url: datas.urlLogin,
            type: 'POST',
            data: {
                user_name: $('#user').val(),
                password: $('#password').val(),
            }
        })
        .done(function(data) {
            var data = JSON.parse(data);
            console.log(data.status);

            if (data.status == 0) {
                alert('账号或密码错误');
            } else {
                login(data.user_info.user_name, data.user_info.teacher_id);
                window.location.href = 'schoollist.php';
            }
        })
        .fail(function() {
            alert('网络错误，请稍后再试');
        })
        .always(function() {
            // console.log("complete");
        });

    }
};
var mounted = function() {
    $('.btn').on('click', function() {
        methods.login();
    });
}

mounted();

</script>
